package com.lcxw.hxzbapi.common;

import com.lcxw.hxzbapi.feign.adminFeignService.AdminService;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.lcxw.hxzbcommon.common.RedisUtils;

/**
 * ywpdapi的配置类
 *
 * @author Administrator
 */

@Configuration
public class YwpdApiConfig implements WebMvcConfigurer {

    @Bean
    public YwpdInterceptor getYwpdInterceptor() {
        return new YwpdInterceptor();
    }

    @Bean
    public RedisUtils getRedisUtils() {
        return new RedisUtils();
    }

    @Bean
    public FilterRegistrationBean repeatedlyReadFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        RepeatedlyReadFilter repeatedlyReadFilter = new RepeatedlyReadFilter();
        registration.setFilter(repeatedlyReadFilter);
        registration.addUrlPatterns("/*");
        return registration;
    }


    /**
     * 拦截器的配置
     *
     * @param registry 入参
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //需要拦截的路径，/**表示需要拦截所有请求
        String[] addPathPatterns = {"/**"};
        //不需要拦截的路径
        String[] excludePathPaterns = {
            "/api/user/login",
            "/api/user/captchalogin",
            "/api/user/register",
            "/api/user/password/forget",
            "/api/user/captcha",
            "/api/user/thirdParty/**",
            "/api/room/create",
            "/api/room/range/**",
            "/api/homepage/**",
            "/api/resource/**",
            "/api/shortVideo/resource/upload",
            "/api/shortVideo/add",
            "/api/shortVideo/getList",
            "/api/shortVideo/getOne",
            "/api/alipay/callback",
            "/api/wxpay/callback",
            "/api/union/login",
            "/api/union/regist",
            "/api/union/pic/upload",
            "/api/union/invoice/upload"
        };
        //注册一个登录拦截器
        registry.addInterceptor(getYwpdInterceptor())
            .addPathPatterns(addPathPatterns)
            .excludePathPatterns(excludePathPaterns);
        //注册一个权限拦截器  如果有多个拦截器 ，只需要添加以下一行代码
        //registry.addInterceptor(new LoginInterceptor())
        // .addPathPatterns(addPathPatterns)
        // .excludePathPatterns(excludePathPatterns);

    }


}
